package com.haojin.spring.service;

import com.haojin.spring.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author .29.
 * @create 2023-02-28 21:21
 */
@Transactional  //事务声明
@Service        //对象生成，存入IOC容器
public class BookServiceImpl implements BookService{

    @Autowired  //自动装备
    private BookDao bookDao;

    @Override
    public void buyBook(Integer bookId, Integer userId) {
        //查询图书的价格
        Integer price = bookDao.getPriceByBookId(bookId);
        //更新图书的库存
        bookDao.updateStock(bookId);
        //更新用户的余额
        bookDao.updateBalance(userId, price);
    }
}
